package cn.jpush.api.utils;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
public class PayHttpClinet {
	public static String  userid = "A943322";
	public static String  pwd	 = "lqy9394123";
	/*public static String  userid = "A943352";
	public static String  pwd	 = "liyong123"*/;
	public static String  KeyStr = "OFCARD";
	Date currentTime = new Date();
	//查询剩余花费
	SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
	public String payfor() throws IOException{ 
		String url = "http://api2.ofpay.com/queryuserinfo.do"; 
	    String host = "http://api2.ofpay.com";  
	    String pwdcp = MD5Util.md5(pwd);
	    String param = "userid="+userid+"&userpws="+pwdcp+"&version=6.0";  
	    HttpClient httpClient = new HttpClient();  
	    httpClient.getHostConfiguration().setHost(host, 80, "http"); 
	    HttpMethod method = getMethod(url, param); 
	    httpClient.executeMethod(method);  
	    String response = method.getResponseBodyAsString();  
	    return response;
	 }
	//手机充值
	public String insertphone(String num,String phonenumber) throws IOException{
		 String url = "http://api2.ofpay.com/onlineorder.do";
		 String host = "http://api2.ofpay.com"; 
		 String uuid = UUID.randomUUID().toString();
		 String times = formatter.format(currentTime);
		 String pwdcp = MD5Util.md5(pwd);
		 String bao = userid+pwdcp+"140101"+num+uuid+times+phonenumber;
		 String md5str = bao+KeyStr;
		 String md5dx = MD5Util.md5dx(md5str);
		 String param = "userid="+userid+"&userpws="+pwdcp+"&cardid=140101&cardnum="+num+"&sporder_id="+uuid+"&sporder_time="+times+"&game_userid="+phonenumber+"&"
		 		+ "md5_str="+md5dx+"&version=6.0";  
		 HttpClient httpClient = new HttpClient();  
	     httpClient.getHostConfiguration().setHost(host, 80, "http"); 
	     HttpMethod method = getMethod(url, param); 
	     httpClient.executeMethod(method);  
	     String response = method.getResponseBodyAsString();
	     System.out.println("MMMMMMMMMMMM");
	     System.out.println(response);
	     System.out.println("MMMMMMMMMMMM");
	    return response;
	}
	//支付宝
	public String insterpaypal(int actprice,String zfb) throws IOException{
		 DecimalFormat df2  = new DecimalFormat("###.0");
		 String url  = "http://api2.ofpay.com/onlineorder.do";
		 String host = "http://api2.ofpay.com"; 
		 String uuid = UUID.randomUUID().toString();
		 String times = formatter.format(currentTime);
		 String pwdcp = MD5Util.md5(pwd);
		 String bao = userid+pwdcp+"6102100"+"1"+uuid+times+zfb;
		 String md5str = bao+KeyStr;
		 String md5dx = MD5Util.md5dx(md5str);
		 String money = df2.format(actprice);
		 String param = "userid="+userid+"&userpws="+pwdcp+"&cardid=6102100&cardnum=1&sporder_id="+uuid+"&sporder_time="+times+"&game_userid="+zfb+"&actprice="
		 +money+"&md5_str="+md5dx+"&version=6.0";
		 HttpClient httpClient = new HttpClient();  
	     httpClient.getHostConfiguration().setHost(host, 80, "http"); 
	     HttpMethod method = getMethod(url, param); 
	     httpClient.executeMethod(method);  
	     String response = method.getResponseBodyAsString(); 
	     System.out.println("TTTTTTTTTTTT");
	     System.out.println(response);
	     System.out.println("TTTTTTTTTTTT");
	     return response;
	}
	//Q币
	public String insterqb(int num,String qq) throws IOException{
		 String url  = "http://api2.ofpay.com/onlineorder.do";
		 String host = "http://api2.ofpay.com"; 
		 String uuid = UUID.randomUUID().toString();
		 String times = formatter.format(currentTime);
		 String pwdcp = MD5Util.md5(pwd);
		 String bao = userid+pwdcp+"220612"+num+uuid+times+qq;
		 String md5str = bao+KeyStr;
		 String md5dx = MD5Util.md5dx(md5str);
		 String param = "userid="+userid+"&userpws="+pwdcp+"&cardid=220612&cardnum="+num+"&sporder_id="+uuid+"&sporder_time="+times+"&game_userid="+qq+"&md5_str="+md5dx+"&version=6.0";
		 HttpClient httpClient = new HttpClient();  
	     httpClient.getHostConfiguration().setHost(host, 80, "http"); 
	     HttpMethod method = getMethod(url, param); 
	     httpClient.executeMethod(method);  
	     String response = method.getResponseBodyAsString();
	     System.out.println("QQQQQQQQQQQQ");
	     System.out.println(response);
	     System.out.println("QQQQQQQQQQQQ");
	     return response;
	}
	//QQ钻石
	public String insterqz(int actprice,String zfb) throws IOException{
			 DecimalFormat df2  = new DecimalFormat("###.0");
			 String url  = "http://api2.ofpay.com/onlineorder.do";
			 String host = "http://api2.ofpay.com"; 
			 String uuid = UUID.randomUUID().toString();
			 String times = formatter.format(currentTime);
			 String pwdcp = MD5Util.md5(pwd);
			 String bao = userid+pwdcp+"6102100"+"1"+uuid+times+zfb;
			 String md5str = bao+KeyStr;
			 String md5dx = MD5Util.md5dx(md5str);
			 String money = df2.format(actprice);
			 String param = "userid="+userid+"&userpws="+pwdcp+"&cardid=6102100&cardnum=1&sporder_id="+uuid+"&sporder_time="+times+"&game_userid="+zfb+"&actprice="
			 +money+"&md5_str="+md5dx+"&version=6.0";
			 HttpClient httpClient = new HttpClient();  
		     httpClient.getHostConfiguration().setHost(host, 80, "http"); 
		     HttpMethod method = getMethod(url, param); 
		     httpClient.executeMethod(method);  
		     String response = method.getResponseBodyAsString();
		     System.out.println("SSSSSSSSSSSS");
		     System.out.println(response);
		     System.out.println("SSSSSSSSSSSS");
		     return response;
		}
	//公用方法
    private static HttpMethod getMethod(String url,String param) throws IOException{  
        GetMethod get = new GetMethod(url+"?"+param); 
        get.releaseConnection();  
        return get;  
    }  
}
